
import { Component, tween, UITransform, v3, _decorator } from 'cc';
const { ccclass, property,menu } = _decorator;

@ccclass
@menu("扩展组件/ComBubbleAction")
export default class ComBubbleAction extends Component {

    //单次移动时间
    @property duration: number = 1;
    
    //移动距离
    @property dis: number = 50;
    

    private posY: number;
    private tween: any;
    onLoad() {
        this.posY = this.node.getComponent(UITransform).node.position.y;
        
    }
    onEnable() {
        this.tween = tween(this.node).repeatForever(tween(this.node)
            .to(this.duration, { position: v3(this.node.getComponent(UITransform).node.position.x, this.posY - this.dis, 0) })
            .to(this.duration, { position: v3(this.node.getComponent(UITransform).node.position.x, this.posY + this.dis, 0) })
        ).start();
    }

    onDisable() {
        if (this.tween) {
            this.tween.stop();
            this.tween = null;
            
            this.node.getComponent(UITransform).node.position.set(this.node.getComponent(UITransform).node.position.x,this.posY);
            
        }
    }
}
